/*
 * Copyright 2009 Biz-e (info@biz-e.nl)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.biz_e.gwt.baselib.ui.client.widgets;

import nl.biz_e.gwt.baselib.client.i18n.Constants;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HorizontalPanel;

/**
 * 
 * @author Joost A. Bloemsma
 */
public class DataButtonBar extends HorizontalPanel implements ClickHandler {
    private final DataButtonBarListener listener;
    private final Button btnNew;
    private final Button btnDelete;
    private final Button btnSave;

    /**
     * Constructs a new DataButtonBar instance
     * 
     * @param listener
     */
    public DataButtonBar(DataButtonBarListener listener) {
        super();
        this.listener = listener;
        btnNew = new Button(Constants.getBaseLib().add(), this);
        btnDelete = new Button(Constants.getBaseLib().delete(), this);
        btnSave = new Button(Constants.getBaseLib().save(), this);
        this.add(btnNew);
        this.add(btnDelete);
        this.add(btnSave);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void onClick(ClickEvent event) {
        Object src = event.getSource();
        if (listener == null)
            return;
        if (src == btnNew)
            listener.onNew();
        if (src == btnDelete)
            listener.onDelete();
        if (src == btnSave)
            listener.onSave();
    }

    /**
     * A listener interface to pass to the DatButtonBar.
     * 
     * @author Joost A. Bloemsma
     */
    public interface DataButtonBarListener {
        /**
         * Triggered when the 'New' button is clicked
         */
        public void onNew();

        /**
         * Triggered when the 'Delete' button is clicked
         */
        public void onDelete();

        /**
         * Triggered when the 'Save' button is clicked
         */
        public void onSave();
    }
}
